/**
 * Created by yaohuan on 2018/4/13 0013.
 */
define(function () {
    var self;
    var fwpjItem ,fwpj;//获取传的参数

    function fwpj_info() {
        self = this;
        self._data = {
            pj: [],
            MMRK003: '',//指标编号  维修及时性
            MMRK004: '',//指标星数
            MMRK005: '无意见', //反馈
            MMRK007: '1',//匿名
            MMRK009:app.cookie('_WX_MOBILE_'),//评价人电话
            MMRK010: '1'//问题处理结果 1解决 2未解决
        };
        self.init();
    }

    //获取评价类型和星数
    fwpj_info.prototype.getStarData = function () {
        self._data.pj.splice(0,self._data.pj.length);
        app.ajax({
            xurl: "api/wx/fwpj/getFwpjList",
            xdata: {
                MMRK001: fwpjItem.MMRDDOCNO,
                MMRK002: fwpjItem.MMRDSEQ,
                MMRJ002: '2'
            },
            cb: function (result) {
                if (result.ok) {
                    self._data.pj.pushArray(result.data.data);
                }
            }
        });
    };

    fwpj_info.prototype.initVue = function () {
        new Vue({
            el: doc.getElementById('content'),
            data: function () {
                return {
                    item: fwpjItem,
                    d: self._data
                }
            },
            methods: {
                pjChange: function (item, v) {
                    item.MMRK004 = v;
                }
            },
            watch: {}
        })
        new Vue({
            el: doc.getElementById('footer'),
            data: function () {
                return {
                    MMRD020 : fwpjItem.MMRD020
                }
            },
            methods: {
                submit: function () {
                    app.confirm({
                        msg: '是否提交评价？',
                        ok: function (e) {
                            app.ajax({
                                xurl: "api/wx/fwpj/saveFwpj",
                                xdata: {
                                    obj: app.jsonString(self._data),
                                    MMRDENT: fwpjItem.MMRDENT,
                                    MMRDDOCNO: fwpjItem.MMRDDOCNO,
                                    MMRDSEQ: fwpjItem.MMRDSEQ
                                },
                                cb: function (result) {
                                    if (result.ok) {
                                        app.alert({
                                            msg: "评价成功!",
                                            ok: function () {
                                                setTimeout(function () {
                                                    app.back(1);
                                                }, 300);
                                            }
                                        });
                                        fwpj.cb();
                                    } else {
                                        app.toast(result.data.message);
                                    }
                                }
                            });
                        }
                    });
                }
            }
        })
    }

    fwpj_info.prototype.init = function () {

        fwpj = app.pageParameters['fwpj-info'];
        fwpjItem = fwpj.item;//获取传的参数

        self.getStarData();

        mui.ready(function () {
            self.initVue();
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });
        })
        mui('.icons').on('tap', 'i', function () {
            var index = parseInt(this.getAttribute("data-index"));
            var parent = this.parentNode;
            var children = parent.children;
            if (this.classList.contains("mui-icon-star")) {    //点击的那个之前如果由空心的星星变成实心的
                for (var i = 0; i < index; i++) {
                    children[i].classList.remove('mui-icon-star');   //star是空心的星星
                    children[i].classList.add('mui-icon-star-filled');  //filled是实心的黄色星星
                }
            } else {
                for (var i = index; i < 5; i++) {  //点击的那个之后由实心的星星变成空心的
                    children[i].classList.add('mui-icon-star')
                    children[i].classList.remove('mui-icon-star-filled')
                }
            }
        });
    }


    return new fwpj_info();
})